package com.digua.base.util

import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Matrix


class ImgUtil {
    companion object {
        fun scaleBitmap(bitmap: Bitmap, width: Int, height: Int, decodeConfig: Bitmap.Config? = Bitmap.Config.ARGB_8888): Bitmap {
            // 创建一个空的Bitmap对象
            val scaledBitmap = Bitmap.createBitmap(width, height, decodeConfig!!)
            // 创建Canvas对象并将放大后的图片绘制在空的Bitmap上
            val canvas = Canvas(scaledBitmap)
            canvas.drawBitmap(bitmap, Matrix(), null)
            // 回收原始Bitmap的内存
            bitmap.recycle()
            return scaledBitmap
        }
    }
}